package com.qf.contller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.qf.pojo.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author lyx
 * @date 2022/7/6 11:47
 */
@RestController
@RequestMapping("/search")
public class SearchContller {
    @RequestMapping("/test")
    public String test1() {
        return "这个微服务被调用到了";
    }

    /**
     * 远程调用带传参
     * @param id
     * @return
     */
    @RequestMapping("/query/{id}")
    @HystrixCommand(fallbackMethod = "findUserIdFallBack")
    public User findUserId(@PathVariable("id")Integer id){
        System.out.println(id);
        User user = new User(2, "张三", new Date());
        //模拟被调用方出错
        int i= 1/0;
        System.out.println(user);
        return user;
    }

    public User findUserIdFallBack(Integer id){
        User user = new User();
        user.setId(2);
        user.setName("出错了");
        user.setBirthday(new Date());
        return user;

    }
}
